package cn.tedu.csmall.order.webapi.controller;

import cn.tedu.csmall.commons.pojo.order.dto.OrderAddDTO;
import cn.tedu.csmall.commons.restful.JsonResult;
import cn.tedu.csmall.order.service.IOrderService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping(("/base/order"))
@Api(tags = "新增订单管理业务")
@Slf4j
public class OrderController {
    @Autowired
    private IOrderService orderService;

    @PostMapping("/add")
    @ApiOperation("新增订单")
    public JsonResult orderAdd(OrderAddDTO orderAddDTO){
        orderService.orderAdd(orderAddDTO);
        return JsonResult.ok("新增订单成功！");
    }

    @PostMapping("/delete")
    @ApiOperation("删除订单")
    @ApiImplicitParams({
            @ApiImplicitParam(value = "商品ID", name = "commodityCode", example = "PU777"),
            @ApiImplicitParam(value = "用户ID", name = "UserId", example = "UU777")
    })
    public JsonResult orderDelete(String commodityCode,String userId){
        orderService.deleteOrder(commodityCode, userId);
        return JsonResult.ok("删除订单完成！");
    }
}
